//
//  MyViewController.m
//  LoveOfPet
//
//  Created by dllo on 15/11/12.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "MyViewController.h"
#import "ZCXCollectViewController.h"
#import "ZCXFeedbackViewController.h"
#import "ZCXOurViewController.h"
#import "AllCollectionViewController.h"

#define HEIGHT  [[UIScreen mainScreen]bounds].size.height / 667
#define WIDTH   [[UIScreen mainScreen]bounds].size.width / 375
@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (retain, nonatomic) UITableView *tableView;

@property (retain, nonatomic) NSArray *array;

@end

@implementation MyViewController

- (void)dealloc{
    [_tableView release];
    [_array release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的萌宠";
    self.view.backgroundColor = [UIColor whiteColor];
    self.array = @[@"我的收藏", @"意见反馈", @"关于我们", @"清除缓存"];

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];

    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];


    [self.tableView release];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60 * HEIGHT;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *index= @"myCellIndentify";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCellIndentify"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:index];
    }
    cell.textLabel.text = self.array[indexPath.row];
    if (indexPath.row == 1) {
        cell.textLabel.userInteractionEnabled = YES;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        AllCollectionViewController *allCollectionViewController = [[AllCollectionViewController alloc]init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:allCollectionViewController animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        [allCollectionViewController release];
    }
    switch (indexPath.row) {
        case 1:{
            ZCXFeedbackViewController *feedback = [[ZCXFeedbackViewController alloc]init];
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:feedback animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            [feedback release];
            break;
        }
        case 2:{
            ZCXOurViewController *our = [[ZCXOurViewController alloc]init];
            [self presentViewController:our animated:YES completion:nil];
            [our release];
            break;
        }
        case 3:{
            NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
            for (NSString *p in files) {
                NSString *path = [NSString stringWithFormat:@"%@/%@", cachePath, p];
                if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
                }
            }
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:nil preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alert animated:YES completion:nil];
            [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(dismissAlert) userInfo:nil repeats:NO];
            
            break;
        }
    }
    
}
- (void)dismissAlert{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)swithBtn
{
    NSLog(@"aa");
}
#pragma mark 设置分割线顶头
-(void)viewDidLayoutSubviews

{
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
        
    }
    
    
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
        
    }
    
}




-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
